# 当前文件测试json文件的读取和访问
from Runtime.elf import ELF
from Runtime.utils import bytes_to_int
from pprint import pprint

# ls = ELF(r'D:\code\pyMachine\Runtime\ls')
ls = ELF(r'.\ls')
# 打印全部elf头中的信息
# for item in dir(ls.elf_header):
#     if r'elf_' in item:
#         print(item,getattr(ls.elf_header,item),len(ls.elf_header))

# 打印全部p header
# print(dir(ls.elf_program_headers[0]))
# print(ls.elf_program_headers[0].segment_type)
#
# for i in ls.elf_section_headers:
#     print(len(i))
print(ls.elf_header.elf_section_header_start_offset)

# print(ls.elf_section_headers[2].Section_name)
# print(ls.elf_section_headers[2].Section_type)

# for item in ls.elf_section_headers:
#     # if r'Section_' in item:
#     #     print(item, getattr(ls.elf_section_headers[i], item))
#     print(item.Section_name,item.Section_type)
# print(ls.address)

# head = {
#     "e_ident": "EI_NIDENT",
#     "e_type": "Elf64_Half",
#     "e_machine": "Elf64_Half",
#     "e_version": "Elf64_Word",
#     "e_entry": "Elf64_Addr",
#     "e_phoff": "Elf64_Off",
#     "e_shoff": "Elf64_Off",
#     "e_flags": "Elf64_Word",
#     "e_ehsize": "Elf64_Half",
#     "e_phentsize": "Elf64_Half",
#     "e_phnum": "Elf64_Half",
#     "e_shentsize": "Elf64_Half",
#     "e_shnum": "Elf64_Half",
#     "e_shstrndx": "Elf64_Half"
# }
# global_type = {
#     "EV_CURRENT": 1,
#     "EI_NIDENT": 16,
#     "Elf32_Addr": 4,
#     "Elf32_Half": 2,
#     "Elf32_Off": 4,
#     "Elf32_Sword": 4,
#     "Elf32_Word": 4,
#     "unsigned_char": 1,
#     "Elf64_Half": 2,
#     "Elf64_Word": 4,
#     "Elf64_Addr": 8,
#     "Elf64_Off": 8,
#
# }
#
# head_list = [
#     "e_ident",
#     "e_type",
#     "e_machine",
#     "e_version",
#     "e_entry",
#     "e_phoff",
#     "e_shoff",
#     "e_flags",
#     "e_ehsize",
#     "e_phentsize",
#     "e_phnum",
#     "e_shentsize",
#     "e_shnum",
#     "e_shstrndx"
# ]
# addr_list = [16, 2, 2,4, 8, 8, 8, 4, 2, 2, 2, 2, 2, 2]
# print(len(addr_list))
# start = 0
# # for item in head_list:
# #     # print(head[item],r'size = ',)
# #     itme_size = global_type[head[item]]
# #     end = start + itme_size - 1
# #     print(start, end, r' name = ', item, r' type = ', head[item], r' size = ', itme_size)
# #     start = end + 1
# for item in addr_list:
#     end = start + item -1
#     print(start, end)
#     start = end + 1
